package com.xjtu.platform.security.loginByMail;

import com.xjtu.platform.common.Result;
import com.xjtu.platform.common.TokenUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/security/loginByMail")
public class LoginByMailAPI {
    @Resource
    private LoginByMailService loginByMailService;

    @PostMapping("")
    public Result loginByMail(@RequestBody LoginByMailDto loginByMailDto){
        boolean ok = loginByMailService.checkLoginMail(loginByMailDto);

        if(ok){
            String web = loginByMailService.getWeb(loginByMailDto);
            String user_id = loginByMailService.getUser_id(loginByMailDto);

            String token = TokenUtils.loginSign(user_id,loginByMailDto.getUser_pwd());
            return Result.success(web,(Object)token);
        }else {
            return Result.fail(Result.ERR_CODE_BUSINESS,"邮箱或者密码错误");
        }

    }
}
